package j2.shopmail;

import android.os.AsyncTask;
import android.view.View;

public class AsycHttp<TP,TR> extends  AsyncTask<TP,Double,TR>
{
    private View UIItem;
    
    
    private AsycHttpAction<TP,TR> backgroundAction;
    
    public void setUIItem(View UIItem)
    {
        
        this.UIItem = UIItem;
    }
    public void PushProgress(double value)
    {
        this.publishProgress(value);
    }
    public View getUIItem()
    {
        return UIItem;
    }
    
    public void setBackgroundAction(AsycHttpAction<TP, TR> backgroundAction)
    {
        this.backgroundAction = backgroundAction;
    }
    
    public AsycHttpAction<TP, TR> getBackgroundAction()
    {
        return backgroundAction;
    }
    
    @Override
    protected void onProgressUpdate(Double... values)
    {
        if(backgroundAction!=null)
            backgroundAction.ProgressUpdateAction(UIItem, values);
        super.onProgressUpdate(values);
    }
    
    @Override
    protected void onPreExecute()
    {
        if(backgroundAction!=null)
            backgroundAction.PreDoFunction();
        super.onPreExecute();
    }
    
    @Override
    protected void onPostExecute(TR tr)
    {
        if(backgroundAction!=null)
             backgroundAction.ResultFunction(tr);
        super.onPostExecute(tr);
    }
    
    @Override
    protected TR doInBackground(TP... tps)
    {
        if(backgroundAction!=null)
            return  backgroundAction.BackGroundAction(tps);
        else
        return null;
    }
}